<?php
include ("includes/header.php");
include ("includes/connection.php");
include ("includes/login.php");
include ("includes/iniciaSessio.php");
?>

<body >
	<?php
	include ("includes/contentHeader.php");
	
	$id = $_GET['id'];

	

	
	/*$sql = "select recorregut.*, r.adresaOrigen, r.adresaFinal, r.idRuta, tipususuari.nomTipusUsuari, usuari.* 
	from((recorregut join usuari on recorregut.idUsuari=usuari.idUsuari) join ruta r on recorregut.idRuta=r.idRuta) 
	join tipususuari on recorregut.idTipusUsuari=tipususuari.idTipusUsuari where r.idRuta=$id";*/
	$sql = "select marca.nom, tipususuari.nomTipusUsuari, vehicle.model, vehicle.matricula, usuari.*,vehicle.idVehicle, recorregut.*, r.* from ((((vehicle join marca on vehicle.idMarca=marca.idMarca)join usuari on vehicle.idUsuari=usuari.idUsuari) join recorregut on usuari.idUsuari=recorregut.idUsuari) join ruta r on recorregut.idRuta=r.idRuta) 
	join tipususuari on recorregut.idTipusUsuari=tipususuari.idTipusUsuari where r.idRuta='$id' and vehicle.eliminat='no'";
	$res = mysql_query($sql, $conexion) or die(mysql_error());
	$row = mysql_fetch_assoc($res);
?>
	<!--contingut 1-->
	<section class="container">
		<!--fons gris-->
		<div class="hero-unit" >
			<h3>Comparteix cotxe entre <?php echo $row['adresaOrigen'];?> i <?php echo $row['adresaFinal'];?> amb <?php echo $row['nomUsuari'];?>.</h3>
			<hr>
							<?php

//$sql = "select marca.nom, vehicle.model, vehicle.matricula, usuari.alias, vehicle.idVehicle from vehicle, marca, usuari where vehicle.idMarca=marca.idMarca and usuari.idUsuari = vehicle.idUsuari and usuari.alias='$alias' and vehicle.eliminat='no'";
				?>
			<TABLE border="0" style="width: 41%; height: 100px;">
				<TR bgcolor="<?php
				if ($row['idTipusUsuari'] == 'CND') {
					echo "#33CCFF";
				}
				if ($row['idTipusUsuari'] == 'PSG') {
					echo "#00CC66";
				}
					?>"><TD colspan="2"><?php echo " " . $row["nomTipusUsuari"];?></TD>
				</TR>
				<TR>
					<TD rowspan="5"><img src="<?php echo $row["foto"];?>" alt="foto" height="150" width="150"/></TD>
				</TR>
				<TR>
					<TD bgcolor="<?php
				if ($row['idTipusUsuari'] == 'CND') {
					echo "LightCyan";
				}
				if ($row['idTipusUsuari'] == 'PSG') {
					echo "#99FFCC";
				}
				?>"> Nom: <?php echo " " . $row["nomUsuari"] . " " . $row["cognom1"] . " " . $row["cognom2"];?></TD>
				</TR>
				<tr>
					<td bgcolor="<?php
				if ($row['idTipusUsuari'] == 'CND') {
					echo "LightCyan";
				}
				if ($row['idTipusUsuari'] == 'PSG') {
					echo "#99FFCC";
				}
				?>"><?php echo "Sexe: " . $row["sexe"];?></td>
				</tr>
				<tr>
					<td bgcolor="<?php
				if ($row['idTipusUsuari'] == 'CND') {
					echo "LightCyan";
				}
				if ($row['idTipusUsuari'] == 'PSG') {
					echo "#99FFCC";
				}
				?>"><?php echo "Data de naixement: " . $row["dataNaixement"];?></td>
				</tr>
				<tr>
				<td bgcolor="<?php
				if ($row['idTipusUsuari'] == 'CND') {
					echo "LightCyan";
				}
				if ($row['idTipusUsuari'] == 'PSG') {
					echo "#99FFCC";
				}
				?>"><?php if ($row['idTipusUsuari'] == 'CND') { echo "vehicle: " . ($row['nom'] .  " - " . $row['model'] .  " - " . $row['matricula'] . "
");}?></td>
				</tr>
				<tr>
					<td colspan="2">
				<?php 
				if (isset($alias))
				{
					$alias = $_SESSION['username'];
				if ($row['alias'] != $alias and $alias==true) {?>
					<button class="btn btn-primary" data-toggle="modal" data-target="#myModal">
						Enviar missatge
					</button></td>
					<?php
					}
					}
					?>
				</tr>
			</TABLE>
			<!--finestre modal-->
			<div  id="myModal" class="modal hide fade">
				<div class="modal-header">
					<a class="close" data-dismiss="modal">×</a>
				</div>
				<div class="modal-body">
					<form class="form-inline" action="#" method="post">
						<div class="control-group">
							Para:
							<br />
							<input readonly="readonly" type="text" name="per" value="<?=$row['alias']
							?>"/>
							<br />
							Asunto:
							<br />
							<input type="text" name="assumpte" />
							<br />
							Mensaje:
							<br />
							<textarea name="text"></textarea>
							</br></br> <a class="enviarFrm btn btn-danger" data-dismiss="modal">Cancel·lar</a>
							<button class="enviarFrm btn btn-success" name="enviarmissatge" type="submit" value="Enviar missatge" >
								Enviar
							</button>
					</form>
					
				</div>
			</div>
			<!--<div class="modal-footer">
			<a href="#" class="btn">Close</a>
			<a href="#" class="btn btn-primary">Save changes</a>
			</div>-->
		</div><!--fi finestra-->
		</div> <!-- fi fons gris-->
	</section>
	<!-- fi contingut 1-->
	<!--contingut 2-->
	<section class="container">
		<div class="hero-unit">
			<h3>Detalls de ruta.</h3>
			<hr>
			<?php
$res = mysql_query($sql, $conexion) or die(mysql_error());
if ($row = mysql_fetch_array($res)) {



			?>
			<table border="1" style="width: 100%; height: 100px;>
			<tr bgcolor="<?php
			if ($row['idTipusUsuari'] == 'CND') {
				echo "#33CCFF";
			}
			if ($row['idTipusUsuari'] == 'PSG') {
				echo "#00CC66";
			}
			?>">
			<th colspan="4" bgcolor="<?php
			if ($row['idTipusUsuari'] == 'CND') {
				echo "#33CCFF";
			}
			if ($row['idTipusUsuari'] == 'PSG') {
				echo "#00CC66";
			}
			?>"><?php if ($row['data'] != '0000-00-00')
						{
							echo $row['data'];
						}
						if ($row['dl'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/lunes_si.png' width='25' height='25'/>";
						}
						if ($row['dl'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/lunes.png' width='25' height='25'/>";
						}
						if ($row['dt'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/martes_si.png' width='25' height='25'/>";
						}
						if ($row['dt'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/martes.png' width='25' height='25'/>";
						}
						if ($row['dc'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/miercoles_si.png' width='25' height='25'/>";
						}
						if ($row['dc'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/miercoles.png' width='25' height='25'/>";
						}
						if ($row['dj'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/jueves_si.png' width='25' height='25'/>";
						}
						if ($row['dj'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/jueves.png' width='25' height='25'/>";
						}
						if ($row['dv'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/viernes_si.png' width='25' height='25'/>";
						}
						if ($row['dv'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/viernes.png' width='25' height='25'/>";
						}
						if ($row['ds'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/sabado_si.png' width='25' height='25'/>";
						}
						if ($row['ds'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/sabado.png' width='25' height='25'/>";
						}
						if ($row['dg'] == '1' and $row['data'] == '0000-00-00') {
							echo "<img src='images/domingo_si.png' width='25' height='25'/>";
						}
						if ($row['dg'] == '0' and $row['data'] == '0000-00-00') {
							echo "<img src='images/domingo.png' width='25' height='25'/>";
						} ?> a les <?php echo $row['hora'];?></th>
			</tr>
			<tr>
			<th rowspan="3"  bgcolor="<?php
			if ($row['idTipusUsuari'] == 'CND') {
				echo "#33CCFF";
			}
			if ($row['idTipusUsuari'] == 'PSG') {
				echo "#00CC66";
			}
			?>"><img src="images/ruta.png" alt='foto' height='70' width='70'/></th>
			<th colspan="3"><?php echo $row['adresaOrigen'];?></th>
			</tr>
			<tr>
			<th colspan="3"><?php echo $row['adresaFinal'];?></th>
			</tr>
			<tr>
			<th>Preu: <?php echo $row['preu'];?>€</th>
			<th><?php
			if ($row['idTipusUsuari'] == 'CND') {
				echo "Nº Places lliures ";
			}
			if ($row['idTipusUsuari'] == 'PSG') {
				echo "Nº Places demandades ";
			}
			?><?php echo $row['nPlaces'];?></th>
			<th><?php
			if ($row['equipatge'] == '1') {
				echo "<img src='images/equipatge_si.png'/>";
			}
			if ($row['equipatge'] == '0') {
				echo "<img src='images/equipatge_no.png'/>";
			}
			if ($row['menjar/beure'] == '1') {
				echo "<img src='images/menjar_si.png'/>";
			}
			if ($row['menjar/beure'] == '0') {
				echo "<img src='images/menjar_no.png'/>";
			}
			if ($row['animals'] == '1') {
				echo "<img src='images/animals_si.png'/>";
			}
			if ($row['animals'] == '0') {
				echo "<img src='images/animals_no.png'/>";
			}
			if ($row['fumador'] == '1') {
				echo "<img src='images/fumador_si.png'/>";
			}
			if ($row['fumador'] == '0') {
				echo "<img src='images/fumador_no.png'/>";
			}
			?>
			</th>
			</tr>
			</table>
			<hr>
			<div id="map_recorregut" style="width: 100%; height: 400px; overflow-x: hidden; overflow-y: hidden; "></div>
				
			
			<?php
			}

$adresaF=$row['adresaFinal'];
 $adresaO=$row['adresaOrigen'];

			?>
			</div>
			</section>
			<?php
if (isset($_POST['enviarmissatge'])) {
	if (isset($_POST['per']) && isset($_POST['assumpte']) && isset($_POST['text'])) {
		$data = date("j/m/Y, g:i a");
		$per = $_POST['per'];
		$de = $_SESSION['username'];
		$assumpte = $_POST['assumpte'];
		$text = $_POST['text'];
		$estat = 0;
		$sql = "insert into missatge (per ,de ,data ,assumpte ,text ,llegit) VALUES ('$per', '$de', '$data', '$assumpte', '$text', '$estat')";
		if (mysql_query($sql, $conexion)) {
			echo "	<script>
alert('Mensaje enviado correctamente');
</script>";
		} else {
			echo "	<script>
alert('Error al enviar mensaje');</script>";
		}
	}
}
?>
			
			<!-- fi contingut 2-->
			<hr>
			
			<?php
			include ("includes/footer.php");
			echo '<script src="./js/mapsdetalle.js"></script>';
		echo "	<script>
			
				//$(document).ready(function() {
					//initialize();
	
		var row1= '". $adresaO."';
		var row2= '".$adresaF."';
		
		
	//	});
				
			</script>";
			
			?>
			
			
			
			
